<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div {
            padding: 10px;
            margin: 30px;
            border: 1px solid brown;
        }
        span {
            border: 1px dashed red;
            margin: 10px;
        }
    </style>
</head>
<body>
    <div>1<hr></div>
    <div>2<hr></div>
    <div>3<hr></div>
    <div>4<hr></div>
    <div>5<hr></div>
    <div>6<hr></div>
</body>
<script src="js/itcast.core.js"></script>
<script src="js/itcast.dom.js"></script>
<script src="js/itcast.ctor.js"></script>
<script>
    var arr = [],
        push = arr.push;
    /*Itcast.fn.appendTo = function(dom){
        dom.appendChild( this[ 0 ] );
        return this;
    }*/

    /*Itcast.fn.appendTo = function(dom){
        this.each(function(i,v){
            return dom.appendChild( this );
        });
        return this;
    }*/

    Itcast.fn.appendTo = function(doms){
        return this.each(function(i,v){
            for ( var i = 0 ; i < doms.length ; i++ ) {
                doms[i].appendChild( i === doms.length -1 ? this : this.cloneNode(true) );
            }
        });
    }




</script>

<script>

    I(
            '<span style="border: 1px dashed red;">span1</span>' +
            '<span style="border: 1px dashed red;">span2</span>' +
            '<span style="border: 1px dashed red;">span3</span>' +
            '<span style="border: 1px dashed red;">span4</span>' +

    '')
    .appendTo( I('div').toArray() );



</script>


</html>